<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	支付日志
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$merchid=$this->checklogin();
$return['statuss']=array(
	'0'=>'待支付',
	'1'=>'已支付',
	'2'=>'支付失败'
);
$return['statuss2']=array(
	array('id'=>0,'title'=>'待支付'),
	array('id'=>1,'title'=>'已支付'),
	array('id'=>2,'title'=>'支付失败')
);
$return['pay_types']=array(
	'wechat'=>'微信支付',
	'wxapp'=>'小程序支付',
	'alipay'=>'支付宝支付',
	'ttpay'=>'头条支付',
	'yinlian'=>'银联支付',
	'credit'=>'余额支付'
);
$return['pay_types2']=array(
	array('id'=>'wechat','title'=>'微信支付'),
	array('id'=>'wxapp','title'=>'小程序支付'),
	array('id'=>'alipay','title'=>'支付宝支付'),
	array('id'=>'ttpay','title'=>'头条支付'),
	array('id'=>'yinlian','title'=>'银联支付'),
	array('id'=>'credit','title'=>'余额支付'),
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid);
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(!empty($_RQ['tid'])){
		$params['tid']=$_RQ['tid'];
		$return['params']['tid']=$_RQ['tid'];
	}
	//支付状态
	if(!empty($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	//支付方式
	if(!empty($_RQ['pay_type'])){
		$params['pay_type']=trim($_RQ['pay_type']);
		$return['params']['pay_type']=$_RQ['pay_type'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$fields=array('id','mid','tid','oid','status','pay_type','createtime','fee','di_fee','plugin');
	$list=pdo_getslice('core_paylog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'支付日志'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'avatar','title'=>'会员头像','type'=>'image'),
			array('name'=>'tid','title'=>'支付单号','type'=>'string'),
			array('name'=>'status','title'=>'支付状态','type'=>'radio','options'=>'statuss'),
			array('name'=>'pay_type','title'=>'支付方式','type'=>'radio','options'=>'pay_types'),
			array('name'=>'createtime','title'=>'发起支付时间','type'=>'time'),
			array('name'=>'fee','title'=>'支付金额','type'=>'string'),
			array('name'=>'di_fee','title'=>'抵扣金额','type'=>'string'),
			array('name'=>'plugin','title'=>'发起支付插件','type'=>'string'),
			array('name'=>'oid','title'=>'插件支付单号','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>10,'title'=>'支付单号','name'=>'tid'),
			array('type'=>'choose','width'=>15,'title'=>'会员ID','name'=>'mid','action'=>'member.get_member/'),
			array('type'=>'select','width'=>15,'title'=>'支付状态','name'=>'status','options'=>'statuss2','help'=>''),
			array('type'=>'select','width'=>15,'title'=>'支付方式','name'=>'pay_type','options'=>'pay_types2','help'=>'','option_key'=>'id','option_title'=>'title'),
			array('type'=>'time_range','width'=>18,'title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择日志！','error');
	}
	$item=cfc('core')->get_member_pay_log($id);
	$member=cfc('core')->get_member($item['mid'],array('nickname','avatar'));
	$item=array_merge($item,$member);
	$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
	$return['item']=$item;
	exi($return);
}